﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>fixed - test</title>
	<script type="text/javascript" src="jquery-1.4.2.js"></script>
	<script type="text/javascript">
if( document.compatMode === 'BackCompat' )
    alert( 'Error:不支持怪异模式,请用主流的XHTML1.0或者HTML5的DOCTYPE申明' );
	
var domRoot = document.documentElement,

compat = function( doc )
{
    doc = doc || document;
	return doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
},

isWindow = function( obj )
{
    return obj && typeof obj === 'object' && 'setInterval' in obj;
},

scroll = function( dom )
{
	/*if( 'pageXOffset' in win )
	{
	    return {
		    x: win.pageXOffset || 0,
			y: win.pageYOffset || 0
		};
	}
	else
	{
	    var d = compat( win.document );
		return {
		    x: d.scrollLeft || 0,
			y: d.scrollTop || 0
		};
	}*/
	return {
	    x: domRoot.scrollLeft,
		y: domRoot.scrollTop
	}
},

docSize = function( elem )
{
    if( isWindow(elem) )
	{
	    //var d = compat( elem.document );
		return {
		    w: domRoot.clientWidth || 0,
			h: domRoot.clientHeight || 0
		};
	}
	else
	{
	    //var d = compat( elem.document );
		return {
		    w: Math.max( domRoot.scrollWidth, domRoot.offsetWidth || 0 ),
			h: Math.max( domRoot.scrollHeight, domRoot.offsetHeight || 0 )
		}
	}
};

var getCurrentStyle = function( obj, name )
{
    if( obj.style && obj.style[name] )
	    return obj.style[name];
	if( document.defaultView && document.defaultView.getComputedStyle )
	{
	    name = name.replace( /([A-Z])/g, '-$1' ).toLowerCase();
		return obj.ownerDocument.defaultView.getComputedStyle(obj,null).getPropertyValue(name);
	}
	else if( obj.currentStyle )
	    return obj.currentStyle[name];
}

window.onload = function()
{
    var s = docSize( window );
	var e = document.getElementById('iDiv');
    alert( getCurrentStyle(document.body,'marginLeft') );	

}
    
	</script>
</head>

<body>
    <div id="iDiv" style="position:absolute;top:50px;left:200px;border:3px solid #f00;width:300px;height:200px;">
	    <div id="title" style="height:28px;background:#00f;margin:2px;"></div>
	</div>
    <div id="iDiv1" style="position:absolute;top:50px;left:700px;border:3px solid #f00;width:300px;height:200px;">
	    <div id="title1" style="height:28px;background:#00f;margin:2px;"></div>
	</div>
    <div style="height:1400px;"></div>	
</body>
</html>